# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=lua51

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.1.5
pkgrel=2
pkgdesc="A powerful light-weight programming language designed for extending applications. Version 5.1.x. (mingw-w64)" 
arch=('any')
url="http://www.lua.org/" 
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs' 'strip' 'emptydirs')
source=($url/ftp/lua-$pkgver.tar.gz)
md5sums=('2e115fe26e435e33b0d5c022e4490567')

build() {
  cd ${srcdir}/lua-${pkgver}

  sed -e 's:llua:llua5.1:' \
    -e 's:/include:/include/lua5.1:' \
    -e "s:/usr/local:${MINGW_PREFIX}:" \
    -i etc/lua.pc\

  sed -r -e '/^LUA_(SO|A|T)=/ s/lua/lua5.1/' \
    -e '/^LUAC_T=/ s/luac/luac5.1/' \
    -e 's/lua.exe/lua5.1.exe/' \
    -e 's/luac.exe/luac5.1.exe/' \
    -e 's/luac.exe/luac5.1.exe/' \
    -i src/Makefile
    
  make -j1 \
    AR="ar rcu" \
    RANLIB="ranlib" \
    STRIP="strip" \
    CC="${MINGW_CHOST}-gcc" \
    INSTALL_TOP="${pkgdir}${MINGW_PREFIX}" \
    INSTALL_DATA='cp -d' \
    INSTALL_INC="${pkgdir}${MINGW_PREFIX}"/include/lua5.1 \
    INSTALL_MAN="${pkgdir}${MINGW_PREFIX}"/share/man/man1 \
    TO_BIN="lua5.1.exe luac5.1.exe lua51.dll" \
    TO_LIB="liblua5.1.a" \
    mingw install
  make clean
}

package(){
  cd ${srcdir}/lua-${pkgver}
  install -Dm644 etc/lua.pc ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/lua5.1.pc
  install -d "${pkgdir}${MINGW_PREFIX}/share/doc/$_realname"
  install -m644 doc/*.{gif,png,css,html} "${pkgdir}${MINGW_PREFIX}"/share/doc/${_realname}
  install -Dm644 COPYRIGHT "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}/COPYRIGHT
  
  cd "${pkgdir}${MINGW_PREFIX}"/share/man/man1
  mv lua.1 lua5.1.1
  mv luac.1 luac5.1.1
}
